package com.htz.java250805_library.controller;

import com.htz.java250805_library.constants.Constants;
import com.htz.java250805_library.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session){
        log.info("用户登录,name" + name);
        //账号和密码不能为空
        if (!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            return false;
        }
        //验证密码是否正确
        //TODO 暂且写死
//        if ("admin".equals(name) && "admin".equals(password)){
//            return true;
//        }

        Boolean isLogin = userService.checkPassword(name, password);
        if (isLogin){
            //存储session
            session.setAttribute(Constants.SESSION_USERNAME,name);
        }
        return userService.checkPassword(name,password);
    }
}



















































